package GUI;
import Control.Shape;
import processing.core.PImage;

public class Button extends Component 
{
	public boolean state;
	public boolean pressed;
	public String label;
	public boolean shapeButton;
	////////////////////////////////////////////////////////////////////////////////////////////////////
	public Button()
	{
		state = false;
		shapeButton=false;
		width =  165;
		height = 25;
	}

	public Button(String string) {
		state = false;
		width =  165;
		height = 25;
		this.label = string;
	}
	public Button(String string,int x,int y) {
		state = false;
		width =  165;
		height = 25;
		this.label = string;
		this.x=x;
		this.y=y;
	}

	public void setLabel(String name){
		label = name;
	}
	public void draw()
	{
		GV.processing.textFont(GV.plotFont, 14);
		int cx = x;
		int cy = y;
		if(label != null)
		{
			width = (int)(GV.processing.textWidth(label)) + 10;
			GV.processing.textAlign(GV.processing.LEFT);

			if(state){
				GV.processing.rectMode(GV.processing.CORNER);
				GV.processing.noStroke();
				GV.processing.fill(120);
				GV.processing.rect(x, y, width, height);
			}


			if(mouseOver()) 
			{
				super.draw();
				if(GV.processing.mousePressed)
				{
					GV.gu.drawBox(x, y, width, height, 0, GV.processing.color(150, 150, 200), 255);
					GV.gu.drawBox(x, y, width, height, 1, GV.processing.color(150, 150, 200), 150);
					cx += 2;
					cy += 2;
					pressed = true;

				}
				else if(pressed)
				{
					pressed = false;
					if(state){state=false; if(label.equals("Cluster")) GV.clusterComputerActivated=false;
					if(shapeButton){
					try {
						GV.shapesPanel.removeShape(GV.shapes.get(Shape.getShapesEnumFromName(label).ordinal()));
					} catch (Exception e) {	e.printStackTrace();}	
					}}
					else {state=true; if(label.equals("Cluster")) GV.clusterComputerActivated=false;
					else if(label.equals("Graphs"))GV.createGraphs();
					if(shapeButton){
					try {
						GV.shapesPanel.addShape(GV.shapes.get(Shape.getShapesEnumFromName(label).ordinal()));
					} catch (Exception e) {	e.printStackTrace();}	
					}}

				}
			}
			else
			{
				pressed = false;
			}

			GV.processing.strokeWeight(1);
			GV.processing.fill(GV.textColor);
			GV.processing.text(label, cx + 5, cy + 20);


		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////

}